package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"news/models"
)

type TypesController struct {
	beego.Controller
}

func (c *TypesController) CreateTypes() {
	name := c.GetString("name")
	types := models.Types{
		Name: name,
	}
	if err := types.GetNewsBy(); err != nil {
		c.Data["json"] = Res{
			Code:    500,
			Data:    nil,
			Message: "系统错误",
		}
		c.ServeJSON()
		return
	}
	types.CreateTypes()
	c.Data["json"] = Res{
		Code:    200,
		Data:    types,
		Message: "新闻添加成功",
	}
	c.ServeJSON()
	return
}
